<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/common.css"/>
		<link rel="stylesheet" type="text/css" href="../css/article_add.css"/>
		<link rel="stylesheet" href="../layui/css/layui.css" media="all"/>
	</head>
	<body>
		<form action="" method="post" id="form" class="search_box">
			<div>
			<span>标题：</span>
			<input type="text" name="title" id="title" placeholder="请输入标题" />
		</div>
			<div>
				<span>摘要：</span>
				<input type="text" name="intro" id="intro" placeholder="请输入摘要" />
			</div>

			<div style="height: auto;">
				<span>内容：</span>
				<div style="flex: 1;">
					<textarea id="editor_id" name="content" style="width: 100%;"></textarea>
				</div>
			</div>
			<button type="submit" class="sub" data-tip = "文章列表">提交</button>
			<button type="reset" class="reset" style="display: none;"></button>
		</form>

		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="../layui/layui.js"></script>
		<script>
				layui.use(['element','form','upload','layedit'], function(){
					var element = layui.element,
					form = layui.form,
					upload = layui.upload,
					layedit = layui.layedit;
					layedit.set({
						uploadImage: {
							url: "/user/content/upload",
							type: 'post'
						}
					});
					layedit.build('editor_id'); //建立编辑器

						$('#form').submit(function (e) {
							$.ajax({
								type: "POST",
								url: "/user/content/edit",
								data: JSON.stringify({title:$("#title").val(),
								       intro:$("#intro").val(),
								       content:$("#editor_id").val()}),
								cache:false,
								 contentType : 'application/json;utf-8',
								processData: false,
								success: function(data){
									if(data){
								//alert(data.msg);
								if(data.rel){
									layui.use('layer', function() {
										var layer = layui.layer;

										layer.msg(data.msg, {
											icon: 6
										},function() {
											var text = $('.sub').attr('data-tip');
									        $(window.parent.$(".acrossTab li").each(function(){
									            if($(this).children('span').text() == text){
									                $(window.parent.$("aside").attr('data-tip',1));
									                $(this).click();
									            } else {
									                $(window.parent.$("aside li").each(function(){
									                    if ($(this).text() == text) {
									                        $(this).click();
									                    }
									                }));
									            }
									        }));
									        $('.reset').click();
										})
									})
								} else {
									layui.use('layer', function() {
										var layer = layui.layer;
										layer.msg(data.msg, {
											icon: 5
										})
									})
								}

							}else{
								layui.use('layer', function() {
									var layer = layui.layer;
									layer.msg('保存失败', {
										icon: 5
									})
								})
							}
								}
							});
							e.preventDefault();
        			});
				});


				$('.lawyer_name').on('input',function(){
					$('.name-list').hide();
					var name = $(this).val();
					if(name.length == 0){
						return false;
					}
					$.ajax({
						type:"get",
						url:"lawyer/list",
						data:{name : name},
						dataType: "json",
						success : function(data){
							var name_list = '';
						 	if(data.rows.length != 0){
						 		for(var i = 0; i< data.rows.length; i++){
						 			name_list += '<li>'+data.rows[i].name+'</li>'
						 		}

						 		$('.name-list').html(name_list).show();

						 		$('.name-list li').click(function(){

						 			$('.lawyer_name').val($(this).text());

						 			$(this).parent('ul').html('').hide();
						 		})

						 	} else {
						 		$('.name-list').html('').hide();
						 	}
						}
					});
				})



		</script>
	</body>
</html>
